package com.zhao.modleclass.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhao.modleclass.R;
import com.zhao.modleclass.activity.HPType1Activity;
import com.zhao.modleclass.activity.Live_Fragment_Activity;
import com.zhao.modleclass.bean.HomePageBean;

/**
 * Created by Administrator on 2016/11/27.
 */
//精选课程适配器
public class HP_SelectedAdapter extends BaseAdapter {
    private Context context;
    private HomePageBean homePageBean;
    private LayoutInflater inflater;

    public HP_SelectedAdapter(Context context, HomePageBean homePageBean) {
        this.context = context;
        this.homePageBean = homePageBean;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return homePageBean.getChosenVideo().size();
    }

    @Override
    public Object getItem(int position) {
        return homePageBean.getChosenVideo().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_hp_selected, parent, false);
            holder = new MyHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyHolder) convertView.getTag();
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int courseId=homePageBean.getChosenVideo().get(position).getCourseId();
                Intent intent=new Intent(context, HPType1Activity.class);
                intent.putExtra("Type",3);
                intent.putExtra("title",homePageBean.getData().get(position).getTitle());
                intent.putExtra("imag_URL",homePageBean.getData().get(position).getImageUrl());
                intent.putExtra("CourseId",courseId);
                context.startActivity(intent);
            }
        });
        Glide.with(context).load(homePageBean.getChosenVideo().get(position).getImageUrl()).into(holder.item_hp_img);
        holder.item_selected_liveTime.setText(homePageBean.getChosenVideo().get(position).getLiveTime() + "");
        holder.item_selected_techJobName.setText(homePageBean.getChosenVideo().get(position).getTechJobName());
        holder.item_selected_techNickName.setText(homePageBean.getChosenVideo().get(position).getTechNickName());
        holder.item_selected_title.setText(homePageBean.getChosenVideo().get(position).getTitle());

        return convertView;
    }

    class MyHolder {
        private ImageView item_hp_img;
        private TextView item_selected_title, item_selected_techNickName, item_selected_techJobName, item_selected_liveTime;

        public MyHolder(View view) {
            item_hp_img = (ImageView) view.findViewById(R.id.item_hp_img);
            item_selected_title = (TextView) view.findViewById(R.id.item_selected_title);
            item_selected_techNickName = (TextView) view.findViewById(R.id.item_selected_techNickName);
            item_selected_techJobName = (TextView) view.findViewById(R.id.item_selected_techJobName);
            item_selected_liveTime = (TextView) view.findViewById(R.id.item_selected_liveTime);
        }
    }
}
